﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TTEditor
{
    public static class EditorWindowMgr
    {
        public class WindowInfo : IWindowInfo
        {
            public IWindow win
            {
                get; set;
            }
            public string ID
            {
                get; set;
            }
            public string title
            {
                get; set;
            }
            public bool show
            {
                get; set;
            }
            public bool candock
            {
                get; set;
            }
            public bool onmenu
            {
                get; set;
            }
        }

        static Dictionary<string, WindowInfo> windows = new Dictionary<string, WindowInfo>();

        public static void AddWindow(string id, string title, IWindow win, bool show = true, bool candock = true, bool onmenu = true)
        {
            var key = id.ToLower();
            if (windows.ContainsKey(key))
                throw new Exception("already have this one.");
            WindowInfo info = new WindowInfo();
            info.win = win;
            info.ID = id;
            info.show = show;
            info.title = title;
            info.candock = candock;
            info.onmenu = onmenu;
            windows[key] = info;
        }
        public static IWindowInfo[] GetAllWindowInfos()
        {
            List<WindowInfo> wins = new List<WindowInfo>();
            foreach (var w in windows.Values)
            {
                if (w.show)
                {
                    wins.Add(w);
                }
            }
            return wins.ToArray();
        }
        public static IWindowInfo GetWindowInfoByID(string id)
        {
            var key = id.ToLower();
            return windows[key];
        }
        public static void ShowWindowByID(string id)
        {
            var key = id.ToLower();

            windows[key].show = true;
            windows[key].win.Show();
        }
        public static void CloseWindowByID(string id)
        {
            var key = id.ToLower();

            windows[key].show = false;
            windows[key].win.OnClose();

        }

    }
}
